#!/bin/bash
# Docker容器执行脚本 - 进入容器或执行命令

set -e  # 遇到错误立即退出

# 容器配置
CONTAINER_NAME="edge-ai-service"
COMMAND=${1:-"bash"}

echo "🔧 进入边侧节点AI服务系统Docker容器..."
echo "📦 容器名称: ${CONTAINER_NAME}"
echo "🎯 执行命令: ${COMMAND}"
echo ""

# 检查Docker是否运行
if ! docker info >/dev/null 2>&1; then
    echo "❌ Docker未运行或无法访问，请检查Docker服务状态"
    exit 1
fi

# 检查容器是否存在并运行
if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
    echo "❌ 容器 ${CONTAINER_NAME} 不存在或未运行"
    echo "💡 请先运行 ./docker-run.sh 启动容器"
    exit 1
fi

# 进入容器
echo "✅ 进入容器..."
if [ "$COMMAND" = "bash" ] || [ "$COMMAND" = "sh" ]; then
    # 交互式shell
    docker exec -it "${CONTAINER_NAME}" /bin/bash
else
    # 执行指定命令
    docker exec -it "${CONTAINER_NAME}" ${COMMAND}
fi 